package dhm.com.dhmshop.adapter.mine;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import dhm.com.dhmshop.R;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.entity.InvoiceBean;
import dhm.com.dhmshop.entity.ShopOrderBean;
import dhm.com.dhmshop.updata.activity.InvoiceaddActivity;
import dhm.com.dhmshop.view.mine.myshop.ShoporderdActivity;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class InvoiceAdapter extends RecyclerView.Adapter<InvoiceAdapter.ViewHolder> {

    private List<InvoiceBean.DataBean> shopList;
    private Context context;


    public InvoiceAdapter(Context context) {
        this.shopList = new ArrayList<>();
        this.context = context;
    }


    public void setShopList(List<InvoiceBean.DataBean> shopList) {
        this.shopList = shopList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view= LayoutInflater.from(context).inflate(R.layout.item_invoice_normal, viewGroup,false);
        viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        viewHolder.invoiceHead.setText(shopList.get(i).getInvoiceHead());
        viewHolder.invoiceCode.setText(shopList.get(i).getInvoiceCode());
        if (shopList.get(i).getInvoiceType()==1){
            viewHolder.invoiceType.setText("增值税专用 ");
            viewHolder.invoiceAddr.setText(shopList.get(i).getInvoiceAddr());
            viewHolder.invoiceBankName.setText(shopList.get(i).getInvoiceBankName());
            viewHolder.invoiceBankNo.setText(shopList.get(i).getInvoiceBankNo());
            viewHolder.invoicePhoneNumber.setText(shopList.get(i).getInvoicePhoneNumber());
            viewHolder.add.setVisibility(View.VISIBLE);
        }else {
            viewHolder.invoiceType.setText("普通发票");
            viewHolder.add.setVisibility(View.GONE);
        }

        viewHolder.del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ondelClick.item(i);
            }
        });

        viewHolder.edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, InvoiceaddActivity.class);
                intent.putExtra("type","1");
                intent.putExtra("bean",shopList.get(i));
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return shopList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public TextView invoiceType;//发票类型
        public TextView invoiceHead;
        public TextView invoiceCode;
        public TextView invoiceAddr;
        public TextView invoicePhoneNumber;
        public TextView invoiceBankName;
        public TextView invoiceBankNo;
        public TextView edit;
        public TextView del;
        public LinearLayout add;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            invoicePhoneNumber=itemView.findViewById(R.id.invoicePhoneNumber);
            invoiceType=itemView.findViewById(R.id.invoiceType);
            invoiceHead=itemView.findViewById(R.id.invoiceHead);
            invoiceCode=itemView.findViewById(R.id.invoiceCode);
            invoiceAddr=itemView.findViewById(R.id.invoiceAddr);
            invoiceBankName=itemView.findViewById(R.id.invoiceBankName);
            invoiceBankNo=itemView.findViewById(R.id.invoiceBankNo);
            edit=itemView.findViewById(R.id.edit);
            del=itemView.findViewById(R.id.del);
            add=itemView.findViewById(R.id.add);
        }
    }

    private OnClick ondelClick;
    public void setdeleteClick(OnClick onClick) {
        this.ondelClick = onClick;
    }
    public interface OnClick{
        void item(int posttion);
    }


    private OneditClick oneditClick;
    public void seteditClick(OneditClick onClick) {
        this.oneditClick = onClick;
    }
    public interface OneditClick{
        void item(int posttion);
    }

    private OnIntentClick onIntentClick;
    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }
    public interface OnIntentClick{
        void item(int posttion);
    }



}

